using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model.DataInterfaces.ServiceDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientServiceController : Controller
    {
		private readonly IAdmissionRepository admissionRepository;
		private readonly IServiceItemRepository serviceitemRepository;
		private readonly IPatientServiceRepository patientserviceRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientServiceController() //: this(new AdmissionRepository(), new ServiceItemRepository(), new PatientServiceRepository())
        {
            admissionRepository = Registry.RepositoryFactory.GetAdmissionRepository();
            serviceitemRepository = Registry.RepositoryFactory.GetServiceItemRepository();
            patientserviceRepository = Registry.RepositoryFactory.GetPatientServiceRepository();
        }

        public PatientServiceController(IAdmissionRepository admissionRepository, IServiceItemRepository serviceitemRepository, IPatientServiceRepository patientserviceRepository)
        {
			this.admissionRepository = admissionRepository;
			this.serviceitemRepository = serviceitemRepository;
			this.patientserviceRepository = patientserviceRepository;
        }

        //
        // GET: /PatientService/

        public ViewResult Index()
        {
            return View(patientserviceRepository.All);//Including(patientservice => patientservice.ServiceItem));
        }

        //
        // GET: /PatientService/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patientserviceRepository.Find(id));
        }

        //
        // GET: /PatientService/Create

        public ActionResult Create()
        {
			ViewBag.PossibleAdmissions = admissionRepository.All;
			ViewBag.PossibleServiceItems = serviceitemRepository.All;
            return View();
        } 

        //
        // POST: /PatientService/Create

        [HttpPost]
        public ActionResult Create(PatientService patientservice)
        {
            if (ModelState.IsValid) {
                patientserviceRepository.Create(patientservice);
                patientserviceRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleAdmissions = admissionRepository.All;
				ViewBag.PossibleServiceItems = serviceitemRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientService/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleAdmissions = admissionRepository.All;
			ViewBag.PossibleServiceItems = serviceitemRepository.All;
             return View(patientserviceRepository.Find(id));
        }

        //
        // POST: /PatientService/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientService patientservice)
        {
            if (ModelState.IsValid) {
                patientserviceRepository.Update(patientservice);
                patientserviceRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleAdmissions = admissionRepository.All;
				ViewBag.PossibleServiceItems = serviceitemRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientService/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patientserviceRepository.Find(id));
        }

        //
        // POST: /PatientService/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var ps = patientserviceRepository.Find(id);
            patientserviceRepository.Delete(ps);
            patientserviceRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

